const whiteUrl = ['https://restapi.amap.com/v3/ip?parameters']
import { showToast } from '@/utils/utils'
import config from '@/http/config'
// const env = require('@/env')
// console.log(env[process.env.MODE])
export default function ({ store, redirect, app: { $axios, $cookies } }) {
    //$axios.defaults.baseURL = 'https://api.test.lilikq.com/ncrm/'
    $axios.defaults.baseURL = config.baseURL
    $axios.defaults.timeout = 3 * 60 * 1000

    $axios.onRequest((config) => {
        //console.log($cookies.get("token"))
        let idx = whiteUrl.findIndex(k => k == config.url);
        let token = $cookies.get("token")
        if (token && idx < 0) {
            config.headers.Authorization = token
        }
    })

    $axios.onError((error) => {
    })

    $axios.onResponse((response) => {
        //console.log('6666666666')
        console.log(response)
        let data = response.data
        // 监控下架的医院、医生、商品、资讯
        if (data.code == '44404') {
            redirect('/nofound');
            return false;
        }
        if (data.code != 200) {
            showToast({
                message: data.message || '出错了',
                type: 'error'
            })
        }
        return Promise.resolve(response.data);
    })
}